Using binary shaders

Use binary shaders to reduce the application loading time. By default Kanzi uses online shaders, which Kanzi exports to an application as source code. When the application loads the shaders it compiles the shaders using the GL driver. This compilation prolongs the loading of the application. When you use binary shaders, Kanzi Studio compiles the shaders when you export the .kzb file from your project and exports them in binary format. Your target device can use binary shaders immediately.

You can use binary shaders only on GPUs that have driver support for binary shaders and you have the shader compiler for the GPU on that device. If the GPU does not support binary shaders, Kanzi Engine compiles shaders from the source. Even though a device may claim support for a specific binary shader format, not all binary shaders are supported.

Using a common binary shader format

To use a common binary shader format:

  1. Identify the GPU vendor, GPU core version, and GPU driver version for the GPU used by your target device, and get the correct binary shader compiler from the GPU vendor.
  2. In the Kanzi Studio in Library press Alt and right-click Materials and Textures > Shader Formats and select Binary Shader Format.

  3. Name the binary shader format after the GPU used by your target device.

    GPU vendorName
    Imagination TechnologiesSGX_BINARY_IMG, or IMG
    ARM MaliMALI_SHADER_BINARY_ARM
    VivanteSHADER_BINARY_VIV
    Digital Media ProfessionalsSHADER_BINARY_DMP
    Fujitsu SemiconductorGCCSO_SHADER_BINARY_FJ
    NVidiaNVIDIA_PLATFORM_BINARY_NV, or Tegra

    If your target device uses any other GPU and you have the shader compiler for that GPU, for instructions on how to create binary shaders contact Rightware's Kanzi support at kanzi.support@rightware.com.

  4. In the Properties set:
    • Enabled property to take the binary shader format into use. When you enable the Enabled property Kanzi Studio compiles the shaders in your Kanzi Studio project when you export the .kzb from your Kanzi Studio project. Kanzi Studio shows in the Log window whether the compilers you use successfully compiled the shaders.
      When you deploy your application to different devices with different GPUs that support binary shaders, enable one binary shader format at a time for each device and export the .kzb file.
    • Vertex Shader Compile to the vertex shader compiler executable for your target device GPU. Use the Kanzi Studio macros to tell the compiler where to store the vertex shader binary.
      For example BinaryShaderCompilerExecutable <vertexshadercode> <vertexshaderbinary>
      Vertex shader code and vertex shader binary are temporary files on the file system. The shader compiler reads from the <vertexshadercode> and writes to <vertexshaderbinary>. If your compiler outputs a binary with a suffix, use a wrapper script to output only the binary without the suffix.
    • Fragment Shader Compile to the fragment shader compiler executable for your target device GPU. Use the Kanzi Studio macros to tell the compiler where to store the fragment shader binary.
      For example BinaryShaderCompilerExecutable <fragmentshadercode> <fragmentshaderbinary>
      Fragment shader code and fragment shader binary are temporary files on the file system. The shader compiler reads from the <fragmentshadercode> and writes to <fragmentshaderbinary>. If your compiler outputs a binary with a suffix, use a wrapper script to output only the binary without the suffix.
    • When a GPU vendor provides a compiler that combines the vertex and fragment shaders, set the shader compiler location and options in the Combined Compile property. For optimal use of resources use either Vertex Shader Compile and Fragment Shader Compile or Combined Compile, but not both. You can find the details for your extension in the Khronos OpenGL registry. When you use Combined Compile use these names.
    • GPU vendorName
      Imagination TechnologiesSGX_PROGRAM_BINARY_IMG
      ARM MaliMALI_PROGRAM_BINARY_ARM
      VivantePROGRAM_BINARY_VIV
      Digital Media Professionals
      • SMAPHS30_PROGRAM_BINARY_DMP
      • SMAPHS_PROGRAM_BINARY_DMP
      • DMP_PROGRAM_BINARY_DMP
      NVidiaNVIDIA_PROGRAM_BINARY_NV
      AMDZ400_BINARY_AMD

Testing binary shaders

To test whether the binary shaders work on your device, start your Kanzi application on your device and check the log. The binary shaders work if in the application log you do not see any errors related to binary shaders.

See also

Reducing shader switches

Optimizing fragment shaders

Loading resources in parallel

Shaders best practices

Measuring the performance of your application

Best practices